<?php
/**
 * File holding the SFTextAreaWithAutocompleteInput class
 *
 * @file
 * @ingroup SF
 */

/**
 * The SFTextAreaWithAutocompleteInput class.
 *
 * @ingroup SFFormInput
 */
class SFTextAreaWithAutocompleteInput extends SFTextAreaInput
{
    public static function getName()
    {
        return 'textarea with autocomplete';
    }

    public static function getDefaultPropTypes()
    {
        return array();
    }

    public static function getParameters()
    {
        $params = parent::getParameters();
        $params = array_merge( $params, SFTextWithAutocompleteInput::getAutocompletionParameters() );
        return $params;
    }

    protected function getTextAreaAttributes()
    {
        $textarea_attrs = parent::getTextAreaAttributes();

        // If 'no autocomplete' was specified, print a regular
        // textarea instead.
        if ( !array_key_exists( 'no autocomplete', $this->mOtherArgs ) ||
            $this->mOtherArgs['no autocomplete'] == false
        ) {
            list($autocompleteSettings, $remoteDataType, $delimiter) = SFTextWithAutocompleteInput::setAutocompleteValues( $this->mOtherArgs );

            if ( !is_null( $remoteDataType ) ) {
                $textarea_attrs['autocompletedatatype'] = $remoteDataType;
            }

            $textarea_attrs['autocompletesettings'] = $autocompleteSettings;

            $textarea_attrs['class'] .= ' autocompleteInput';
        }

        //Values from query
        if ( array_key_exists( 'values from query', $this->mOtherArgs ) ) {
            $textarea_attrs['vfq'] = $this->mOtherArgs['values from query'];
            $textarea_attrs['class'] .= ' ValuesFromQueryTarget';
            //If there some substitution, we pass it to tag parameters
            if ( array_key_exists( 'substitution', $this->mOtherArgs ) ) {
                $textarea_attrs['vfqs'] = $this->mOtherArgs['substitution'];
            }
        }

        return $textarea_attrs;
    }
}
